package com.wxxymakers.cklabrecruit.utils;

import org.springframework.util.Base64Utils;
import org.springframework.util.StringUtils;

import java.nio.charset.StandardCharsets;

/**
 * @AUTHOR soft
 * @DATE 2018/11/30 21:32
 * @DESCRIBE
 */
public class Utils {

    public static String toBase64(String source) {
        return Base64Utils.encodeToString(source.getBytes());
    }

    public static String fromBase64(String base64) {
        byte[] bytes = Base64Utils.decodeFromString(base64);
        return new String(bytes, StandardCharsets.UTF_8);
    }

    public static String tos(Object...os) {
        StringBuilder builder = new StringBuilder();
        for (Object o : os) {
            builder.append(o).append("_");
        }
        return toBase64(builder.toString());
    }

    public static String[] froms(String bs) {
        String source = fromBase64(bs);
        if (!StringUtils.isEmpty(source)) {
            return source.split("_");
        }
        return null;
    }

    public static boolean isZero(Integer num) {
        return num == null || num <= 0;
    }
}
